﻿@model IEnumerable<duanzhi.web.Models.article>
@using duanzhi.web.Models;
@using publicLibrary;

@{
    var tags = ViewBag.tags as IQueryable<tag>;
    pageNav pn = ViewBag.pageNav as pageNav;
    ViewBag.Title = "Index";

}

<script src="~/Scripts/jquery-1.7.1.min.js" ></script>
<link type="text/css" rel="stylesheet" href="~/Content/themes/base/jquery-ui.css" />

<script src="~/Scripts/jquery-ui-1.8.20.js"></script>
<script src="~/Content/ckeditor/ckeditor.js" ></script>

@*<script src="~/Content/wordPaster/WordPaster.forCKeditor.js"></script>*@
@*<link type="text/css" rel="stylesheet" href="~/Content/wordPaster/WordPaster.css" />*@

<script>
    var asLiveImgPasterClient = function () {
        this.postUrl = "";
        this.maxSize = 6000; //k为单位
        this.compeleteFun =null;
        this.progressFun = null;
        this.init.apply(this, arguments);
    }
    asLiveImgPasterClient.prototype = {
        isHas:function(){
            if (window.asLiveImgPaster == undefined) {
                alert("浏览器中不存在asLiveImgPaster组件");
                return false;
            }
            return true;
        },
        init: function (url,callFun, progressFun,maxSize) {
            if (typeof(url)!="undefined") {
                this.postUrl = url;
            }
            if (typeof(maxSize) != "undefined" && maxSize > 0) {
                this.maxSize = maxSize
            }
            if(typeof(callFun)!="undefined"){
                this.compeleteFun = callFun;
            }
            if (typeof (progressFun) != "undefined") {
                this.progressFun = progressFun;
            }
        },
        post: function () {
            if (this.postUrl == "") {
                alert("请先配置目标地址");
                return;
            }
            if (this.isHas) {
                window.asLiveImgPaster.maxSize=this.maxSize;
                var xx = window.asLiveImgPaster.paster(this.postUrl, this.compeleteFun, this.progressFun);
                if (xx == true) {
                    this.CallProgressFun();
                }
            }
        },
        CallProgressFun: function (_this) {
            if (!_this) {
                _this = this;
            }
            if (_this.progressFun != null) {
                var progress = window.asLiveImgPaster.progress;

                _this.progressFun(progress);
                if (progress != 100) {
                    _this._setTimeout(_this.CallProgressFun, 500,_this)
                } else {
                    _this.CallCompeleteFun();
                }
            }

        },
        CallCompeleteFun: function () {
            

            if (this.compeleteFun != null) {
                
                this.compeleteFun(window.asLiveImgPaster.fileUrl)
            }
        },
        _setTimeout: function (fRef, mDelay) {
            if (typeof fRef == 'function') {
                var argu = Array.prototype.slice.call(arguments, 2);
                var f = (function () { fRef.apply(null, argu); });
                return setTimeout(f, mDelay);
            }
            return setTimeout(fRef, mDelay);
        }

    }
    //调用方法
    function callImgPasterUpload() {
        var x = new asLiveImgPasterClient("http://localhost:6259/a/TP",c,p);
        x.post()

    }
    //imgParsterUpload进度
    function p() {
        //alert("进度:"+arguments[0]);
    }
    //imgParsterUpload完成
    function c(s) {

        CKEDITOR.instances.content.setData(CKEDITOR.instances.content.getData() + "<img src='" + s + "' />");

    }

</script>
<button onclick="$('#articleForm').show()" class="big">分享段子</button>

<div id="articleForm" class="color0b">
    <div style="text-align:right" class="color1b"><button onclick="$('#articleForm').hide()" style="margin-right:0px" class="color2b">关闭</button></div>
    <fieldset style="overflow-y:scroll; height:455px ">
        <legend>段子提交</legend>
        <form action="/a/aa" method="post" id="articleFormF" >
                    <input type="hidden" name="aID" id="aID" />
                    <input type="hidden" name="datatime" id="datatime" />
                    
        <table style="width:100%">
        
            <tr>
                <td style="text-align:right">标题：</td>
                <td>
                    <input type="text" value="" name="title" id="title"/>通常为空，如果title存在。则首先显示
                </td>
            </tr>
            <tr>
                <td style="text-align:right">内容：
                    <br />
                    (通常都写在这里)
                </td>
                <td style="width:600px;">
                    <textarea name="content" id="content" ></textarea>
                    
                </td>
            </tr>
            <tr>
                <td style="text-align:right">标签：</td>
                <td>
                    <input value="" type="text" name="tagsStr" id="tagStr"/><button type="button" onclick="callImgPasterUpload()">剪切板图片上传</button>
                    <div onclick="pushTag(event)" class="tags">
                        @foreach (tag t in tags) { 
                            <label>@t.name</label>
                        }
                    </div>
                </td>
            </tr>
            <tr>
                <td style="text-align:right">作者：</td>
                <td>
                    <input value="" name="userID" id="userID" type="hidden" />
                    <input value="" name="userName" id="userName" type="text" class="small" />
                    来至：<input value="" name="from" type="text" class="small" id="from" />
                </td>

            </tr></table>
            <div style="text-align:right"><button type="button" onclick="articleSubmit()" style="width:100px">提交</button></div>
    </form>
        <div style="padding-left:20px; color:gray; font-style:italic; font-size:12px;">若要使用剪切板图片直接上传，请下载<a href="/Content/asliveImgPaster.rar">asLive剪切板图片上传插件ForIE</a>，并保存一固定地方，运行reg.bat。本插件为自主开发，网页的自动安装注册不会弄。只要打包手动安装，该插件只在duanzhi表单中点击“剪切板图片上传”按钮时责任读取剪切板中的图形类数据，并上传，再无任何代码。请放心使用，如对你的系统造成安全性危害，你可以砸我家玻璃
            <p>
            备：支持Gif动画的上传、png的无损上传
            bug反馈，或砸我家玻璃请联系QQ：738337460;windbell0412#sina.com
            </p>



        </div>
    </fieldset>


</div>
<script>

        CKEDITOR.replace('content',
        {

            toolbar:
            [
                ['Bold', 'Italic', '-', 'BulletedList', '-', 'Link', 'Unlink', '-', 'Source', 'Image', 'Maximize'],


            ]
            , toolbarLocation: "bottom"
            , height: 100
            , filebrowserImageUploadUrl: "/a/TPCK/"
        });

</script>
<div id="as">

@foreach (var item in Model) {
    <div class="article">
    @if(!String.IsNullOrWhiteSpace(item.title)){
        <div class="title">@item.title</div>
        <div class="content">@Html.Raw(item.content)</div>

    }else{
       <div class="title">@Html.Raw(@item.content)</div>
    }
        <div style="font-size:12px;" class="clear-fix">
            <div style="float:right">推荐人:@@@item.userName 赞：@item.recommend <button onclick="showReply(this,'@item.Id')">回复</button> <button onclick="editA('@item.Id')">修改</button> <button onclick="if(confirm('确认删除')){window.location.href='/a/Da/@item.Id'}">删除</button></div>
            @if(item.tags!=null){<div class="tags">@String.Join(",",item.tags)</div>}
            <div><span class="date">@item.datetime  </span>
             @if(!string.IsNullOrWhiteSpace(item.from)){
                 <span>来至:@item.from</span>
             }
            </div>
            
        </div>

        @if (item.reply != null)
        {
        <ul class="replys">
            @foreach (var reply in (item.reply).OrderByDescending(d => d.datetime))
            {
            <li>
                @@@reply.userName：@reply.content  &#160;&#160;&#160;&#160;<span class="date">[@item.datetime]</span>
            </li>
            }
        </ul>
        }
        
    </div>
}
</div>
<div style="text-align:right">
    <button type="button" onclick="window.location.href='/a/index?pageIndex=@(++pn.pageIndex)&@(Request["key"]!=null?"key="+Request["key"]:"")'" > 下一页 </button>
</div>

        <div style="display:none" id="replyForm" aID="">
            作者：<input value="" name="userName" class="small" id="replyUserName" /><input type="hidden" value="" name="replyUserID" />
            回复：<input name="replyContent" id="replyContent"/>
            <button onclick="submitReply(this)">提交</button>
        </div>
        
    <script type="text/javascript" src="~/Content/js/a.js"></script>